package com.ebs.md.fxmonitor.marketmonitor.adapter;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/adapter/TOB2EsperAdapter.java $
 *  $Revision: #1 $  $Change: 114793 $  $DateTime: 2012/09/10 13:37:00 $  $Author: Arik.Sher $
 */

import com.ebs.commons.comp.IParsedPayload;
import com.ebs.md.api.BookSide;
import com.ebs.md.api.OrderSide;
import com.ebs.md.fxmonitor.marketmonitor.AbstractMonitorListenerAndForwarder;
import com.ebs.md.fxmonitor.marketmonitor.CommonPayloadParse;
import com.ebs.md.fxmonitor.marketmonitor.model.TOBState;


public class TOB2EsperAdapter
extends AbstractMonitorListenerAndForwarder<TOBState>
{

	/**
	 * 
	 * @see com.ebs.md.fxmonitor.orders.TopOfBooksChangeListener#createBasicNotificationPayload
	 */
	protected TOBState transform(IParsedPayload payload) {
		OrderSide orderSide = CommonPayloadParse.getOrderSide(payload);
		
		TOBState tobState = new TOBState(
			 CommonPayloadParse.getActionTime(payload)
			,CommonPayloadParse.getPair(payload)
			,BookSide.fromOrderSide(orderSide)
			
			,CommonPayloadParse.getTopRateBySide(payload, orderSide)
			,CommonPayloadParse.getTopRateBySide(payload, orderSide.getOtherSide())
			
			,CommonPayloadParse.getPreviousTopRateBySide(payload, orderSide)
		);

		return tobState;
	}

	@Override
	public void init() {
		super.init();
		logger.info(getClass().getSimpleName() + ": ready for use");
	}

	
}
